home *** CD-ROM | disk | FTP | other *** search
- MAIN LANGUAGE FEATURES EXEMPLIFIED
- ==================================
-
-
- 1. Line Format
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Where to ║free ║free ║columns 7-72: code ║free ║
- ║write ║ ║ ║cols 2-5: number label ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║More than ║No for ║OK ║Never ║OK ║
- ║1 commands║certain ║ ║ ║ ║
- ║per line? ║instructions ║ ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║At end of ║: if another ║; ║Nothing ║; ║
- ║command ║' if remark ║ ║ ║ ║
- ║ ║follows ║ ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Remark ║i=5 'initially║i=5;/* initial║ i = 5 ║i=5{initially}║
- ║ ║'to end of ║ value */ ║C initially ║; ║
- ║ ║'line ║ ║C C in 1st column ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Continued ║print _ ║fprintf( ║ write(*,*) ║writeln( ║
- ║command ║NQ(1) ║"%d\n", ║ +NQ(1) ║NQ(1)); ║
- ║ ║ ║NQ(1)); ║C put + at 6th col ║ ║
- ║ ║ ║#define Y "in\║ ║ ║
- ║ ║ ║ #define only"║ ║ ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
- 2. Program Structure
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Main ║'No special ║main() { ║ program main ║begin ║
- ║program ║'structure ║... ║ ... ║... ║
- ║ ║ ║} ║ end ║end. ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Function ║function x(d) ║int x(d) ║ integer function x(d)║function x(d: ║
- ║body ║ x = d ║double d; ║ real*8 d ║ real): ║
- ║ ║end function ║{ int x; ║ x = d ║ integer; ║
- ║ ║ ║ x = d; ║ return ║begin ║
- ║ ║ ║ return(x); ║ end ║ x := d; ║
- ║ ║ ║} ║ ║end; ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Subroutine║sub d(x) ║void d(x) ║ subroutine d(x) ║procedure ║
- ║body ║ print x ║int x; ║ integer x ║ d(x:integer) ║
- ║ ║end sub ║{ printf("%d",║ write(*,*)x ║begin ║
- ║ ║ ║ x); ║ return ║ writeln(x); ║
- ║ ║ ║} ║ end ║end; ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
-
- 3. Using Subroutines
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Declaring ║declare sub _ ║/*ANSI:*/ ║C not generally ║procedure ║
- ║subroutine║ e(m, s) ║void e(int, ║C needed ║e(m,s:integer)║
- ║ ║declare sub _ ║ int); ║ ║; forward; ║
- ║ ║ f () ║void f(void); ║ ║procedure f; ║
- ║ ║ ║/*old style:*/║ ║forward; ║
- ║ ║ ║void e(); ║ ║ ║
- ║ ║ ║void f(); ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Calling ║e m, s ║e(m,s); ║ call e(m,s) ║e(m,s); ║
- ║subroutine║f ║f(); ║ call f ║f; ║
- ║(f has no ║ ║ ║ ║ ║
- ║arguments)║ ║ ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Declaring ║declare _ ║/*ANSI:*/ ║C not generally ║function ║
- ║function ║ function _ ║int y(int; ║C needed ║y(m,s:integer)║
- ║ ║ y(m, s) ║ int); ║ ║: integer; ║
- ║ ║declare _ ║int z(void); ║ ║forward; ║
- ║ ║ function _ ║/*old style:*/║ ║function z: ║
- ║ ║ z () ║int y(); ║ ║integer; ║
- ║ ║ ║int z(); ║ ║forward; ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Calling ║i = y(m,s) ║i = y(m,s); ║ i = y(m,s) ║i := y(m,s); ║
- ║function ║i = z ║i = z(); ║ i = z() ║i := z; ║
- ║(z has no ║ ║ ║ ║ ║
- ║arguments)║ ║ ║ ║ ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
-
- 4. Declarations
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Declaring ║common _ ║int s, f ║ common s,f ║s,f:integer; ║
- ║global ║shared s, f ║/* declare not║ ║{ declare ║
- ║variables ║ ║ inside any ║ ║ before any ║
- ║ ║ ║ routine */║ ║ routine } ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Constants ║const a = 1 ║#define a 1 ║C not available ║const a = 1; ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Boolean ║const FALSE=0_║#define TRUE 1║ .true. ║true ║
- ║constants ║ TRUE = not _ ║#define FALSE\║ .false. ║false ║
- ║ ║ FALSE ║ 0 ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Basic ║i% 'Last ║int i; ║ integer i ║i:integer; ║
- ║types ║a! 'character ║float a; ║ real a ║a:real; ║
- ║ ║d# 'indicates ║double d; ║ real*8 d ║d:real*8; ║
- ║ ║c$ 'type ║char c[8]= ║ character*8 c ║c:string[8]; ║
- ║ ║ ║ "Hi!"; ║ logical l ║l:boolean; ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Array ║dim a(1 to 20)║float a[20] ║ real a(20) ║a:array[20] of║
- ║ ║ ║ ║ ║ real; ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
-
- 5. Basic Operations
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Integer ║i = 4 \ 2 ║i = 4 / 2 ║ i = 4 / 2 ║i = 4 div 2 ║
- ║division ║ ║ ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Raising to║i = 2 ^ 3 ║i = pow(2.0, ║ i = 2**3 ║i = exp(3 * ║
- ║power ║ ║ 3.0); ║ ║ ln(2)) ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Modulo ║i = 5 mod 2 ║i = 2.0 * ║ i = mod(5,2) ║i = 5 mod 2 ║
- ║ ║ ║ modf(5.0/2.0,║ ║ ║
- ║ ║ ║ &j); ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Boolean ║(i<>5 or j=6)_║(i!=5 || j==6)║ (i.ne.5.or.j.eq.6). ║(i<>5 or j=6) ║
- ║expression║ and (k<=8 or_║ && (k<=8 || ║ +and.(k.le.8.or. ║ and (k<=8 or ║
- ║ ║ a>=9 or b<0)_║ a>=9 || b<0) ║ +a.ge.9.or.b.lt.0) ║ a>=9 or b<0) ║
- ║ ║ and c<-1 ║ && c<-1 ║ +.and.c.lt.-1 ║ and c<-1 ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Assignment║i = 3 ║i = 3; ║ i = 3 ║i := 3; ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
-
- 6. Controlling Order of Execution
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Execution ║if i < 1 _ ║if (i<1) ║ if (i.lt.1) then ║if i<1 then ║
- ║under a ║then x = 1 _ ║ x = 1; ║ x = 1 ║ x = 1 else ║
- ║condition ║else x = -i ║else x = -i; ║ else ║ x = -i; ║
- ║ ║ ║ ║ x = -i ║ ║
- ║ ║ ║ ║ endif ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Repeated ║for i=1 to 3 ║for(i=0;i<3; ║ do 9 i=1,3 ║for i:=1 to 3 ║
- ║fixed ║ j = j * 2 ║ i++) ║ j = j * 2 ║ do ║
- ║number of ║next i ║ j = j * 2; ║9 continue ║ j = j * 2; ║
- ║times ║ ║ ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Loop, ║while i < 10 ║while (i < 10)║9 continue ║while i<10 do ║
- ║condition ║ i = i + 1 ║{ ║ if (i.lt.10) then ║begin ║
- ║at top ║wend ║ i = i + 1; ║ i = i + 1 ║ i := i + 1; ║
- ║ ║ ║} ║ goto 9 ║end; ║
- ║ ║ ║ ║ endif ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Loop, ║do ║do ║9 continue ║repeat ║
- ║condition ║ i = i + 1 ║{ ║ i = i + 1 ║ i = i + 1 ║
- ║at bottom ║loop while _ ║ i = i + 1; ║ if (i.lt.10) goto 9 ║until i >= 10 ║
- ║ ║ i < 10 ║}while (i<10);║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Multiple ║select case i ║switch(i) { ║ goto (1,2) i ║case i of ║
- ║branch ║ case 1 ║case 1: ║1 j = 2 ║ 1: j = 2; ║
- ║ ║ j = 2 ║ j=2; break; ║ goto 8 ║ 2: j = j*2; ║
- ║ ║ case 2 ║case 2: ║2 j = j*2 ║end; ║
- ║ ║ j = j*2 ║ j=j*2; break;║ goto 8 ║ ║
- ║ ║end select ║} ║8 continue ║ ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝
-
-
-
- 7. Input / Output
-
- ╔══════════╦══════════════╦══════════════╦═══════════════════════╦══════════════╗
- ║ Feature ║ BASIC ║ C ║ FORTRAN ║ Pascal ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Writing ║print i ║printf("%d\n",║ write(*,*) i ║writeln(i); ║
- ║to screen ║ ║ i) ║ ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Writing ║open "d.out"_ ║f = fopen( ║ open(unit=7,file= ║assign(f, ║
- ║to disk ║ for output _ ║ "d.out","w");║ +'d.out',mode='WRITE',║ 'd.out'); ║
- ║ ║ as #1 ║fprintf(f, ║ +status='NEW') ║rewrite(f); ║
- ║ ║print #1,i,j ║ "%d %d\n", ║ write(7,1)i,j ║writeln(i, ║
- ║ ║close #1 ║ i,j); ║1 format(I5,I5) ║ ' 'j); ║
- ║ ║ ║fclose(f); ║ close(7,status= ║close(f); ║
- ║ ║ ║ ║ +'KEEP') ║ ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Reading ║input;"please_║scanf( ║ write(*,'A\') ║write( ║
- ║from ║ enter";i,j ║ "%d %d", ║ +'please enter ' ║ 'please:'); ║
- ║keyboard ║ ║ i, j); ║ read(*,*)i,j ║readln(i,j); ║
- ╠══════════╬══════════════╬══════════════╬═══════════════════════╬══════════════╣
- ║Reading ║open "i.inp"_ ║f= fopen( ║ open(unit=8,file= ║assign(f, ║
- ║from ║ for input _ ║ "i.inp","r");║ +'i.inp',mode='READ', ║ 'i.inp'); ║
- ║disk ║ as #1 ║fscanf(f, ║ +status='OLD') ║reset(f); ║
- ║ ║input #1,a,b ║ "%7.0f %7.0f"║ read(8,2)a,b ║readln(f,a,b);║
- ║ ║close #1 ║ ,a,b); ║2 format(F7.0,F7.0) ║close(f); ║
- ║ ║ ║fclose(f); ║ close(8) ║ ║
- ╚══════════╩══════════════╩══════════════╩═══════════════════════╩══════════════╝